using OracleInternal.Json.Binary;
using OracleInternal.Json.Common;

namespace OracleInternal.Json.Sql
{
	internal class OracleJsonIntervalYM : OracleJsonValue
	{
		internal const int INTERVALYM_LEN = 5;

		private byte[] m_raw;

		internal OracleJsonIntervalYM(byte[] raw)
		{
			m_raw = raw;
		}

		internal OracleJsonIntervalYM(Period p)
		{
			m_raw = OsonPrimitiveConversions.PeriodToIntervalYM(OracleJsonExceptions.ORACLE_FACTORY, p);
		}

		public override OracleJsonType GetOracleJsonType()
		{
			return OracleJsonType.INTERVALYM;
		}

		public override string ToJsonString()
		{
			return OracleJsonSerializer.SerializeString(GetJsonString());
		}

		internal string GetJsonString()
		{
			return OsonPrimitiveConversions.SerializeIntervalYM(OracleJsonExceptions.ORACLE_FACTORY, Raw());
		}

		internal byte[] Raw()
		{
			return m_raw;
		}

		internal Period GetPeriod()
		{
			return OsonPrimitiveConversions.IntervalYMToPeriod(Raw());
		}

		internal static string SerializePeriod(Period p, IExceptionFactory f)
		{
			byte[] raw = OsonPrimitiveConversions.PeriodToIntervalYM(f, p);
			return OsonPrimitiveConversions.SerializeIntervalYM(f, raw);
		}

		internal OracleJsonIntervalYM GetINTERVALYM()
		{
			return this;
		}
	}
}
